package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.AdminOrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@Slf4j
@RestController
@RequestMapping("/admin/order")
@Api(tags = "管理员订单查询")
public class OrderController {

    @Autowired
    private AdminOrderService adminOrderService;

    /**
     * 订单搜索 分页查询
     * 条件 分页查询订单
     * @param dto
     * @return
     */
    @ApiOperation("分页查询")
    @GetMapping("/conditionSearch")
    public Result<PageResult> get( OrdersPageQueryDTO dto) {
        log.info("分页查询参数{}",dto);
        return adminOrderService.get(dto);
    }

    /**
     * 各个状态的订单数量统计
     * @return
     */
    @ApiOperation("状态订单数量统计")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> getStatus() {
        OrderStatisticsVO vo = adminOrderService.countStatus();
        return Result.success(vo);
    }

    @ApiOperation("查询订单详情")
    @GetMapping("/details/{orderId}")
    public Result<OrderVO> getOrder(@PathVariable("orderId") Long orderId) {
        log.info("请求参数{}",orderId);
        OrderVO vo = adminOrderService.getOrder(orderId);
        return Result.success(vo);
    }

    @ApiOperation("取消订单")
    @GetMapping("/cancel")
    public Result quXiao(@RequestBody OrdersCancelDTO dto) {
        log.info("取消订单请求参数{}",dto);
        adminOrderService.quXiao(dto);
        return Result.success();

    }

    @ApiOperation("拒绝订单")
    @PutMapping("/rejection")
    public  Result juJue(@RequestBody OrdersRejectionDTO dto){
        log.info("拒绝订单请求参数{}",dto);
        adminOrderService.juJue(dto);
        return Result.success();

    }


}
